/**
 * 
 */
package sg.edu.nus.iss.jass.gui;

import java.awt.Dimension;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DebugGraphics;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SwingConstants;

import sg.edu.nus.iss.jass.controller.JobAdvertisementController;
import sg.edu.nus.iss.jass.controller.JobSearchController;
import sg.edu.nus.iss.jass.dto.Company;
import sg.edu.nus.iss.jass.dto.GeographicalLocation;
import sg.edu.nus.iss.jass.dto.Skill;

/**
 * @author Jeanie
 *
 */
public class AddJobPanel extends JPanel{
	
	private MainFrame mainFrame;
	private JobAdvertisementFormPanel parent;
	private JobAdvertisementController jobAdvertisementController;
	
	private List<Skill> skills;
	private List<Company> companies;
	private List<GeographicalLocation> locations;
	
	private JLabel functionTitleLbl;
	private JLabel jobIDTitleLbl;
	private JLabel statusLbl;
	private JLabel creationDateLbl;
	private JLabel creationDateTitleIbl;
	private JLabel jobIDLbl;
	private JLabel jobTitleLbl;
	private JLabel jobDescriptionTitleLbl;	
	private JLabel yearsOfExpTitleLbl;
	private JLabel startDateLbl;
	private JLabel skillsLbl;	
	private JLabel locationLbl;	
	private JLabel salaryRangeLbl;
	private JLabel hideSalaryLbl;		
	
	private JTextField titleTextField;
	private JTextField startDateTxtField;
	private JTextField yearsOfExpTxtField;	
	
	private JTextArea descriptionTxtArea;

	private JComboBox isStatusCbx;
	private JComboBox salaryRangeCbx;
	private JComboBox isHideSalaryCbx;	

	private JList skillsJList;	
	private JList locationJList;		
	
	public AddJobPanel(MainFrame mainFrame, JobAdvertisementFormPanel parent){
		this.mainFrame = mainFrame;
		this.parent = parent;
		this.createAddJobPanel();		
	}	
	private void createAddJobPanel() {
		// TODO Auto-generated method stub
		setPreferredSize(new Dimension(800, 550));
		this.setLayout(null);
		this.setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
		this.setFont(new java.awt.Font("Arial",0,12));
		
			functionTitleLbl = new JLabel();
			this.add(functionTitleLbl);
			functionTitleLbl.setText("Add Job Advertisement Function");
			functionTitleLbl.setFont(new java.awt.Font("Arial Rounded MT Bold",0,20));
			functionTitleLbl.setBounds(245, 18, 318, 24);		
		
			creationDateTitleIbl = new JLabel();
			this.add(creationDateTitleIbl);
			creationDateTitleIbl.setText("Creation Date:");
			creationDateTitleIbl.setBounds(31, 74, 150, 21);
			creationDateTitleIbl.setFont(new java.awt.Font("Arial",0,18));		
		
			creationDateLbl = new JLabel();
			this.add(creationDateLbl);
			creationDateLbl.setText("23th Oct  2011");
			creationDateLbl.setBounds(221, 74, 150, 21);
			creationDateLbl.setFont(new java.awt.Font("Arial",0,18));
			creationDateLbl.setHorizontalAlignment(SwingConstants.LEFT);		
		
			jobIDTitleLbl = new JLabel();
			this.add(jobIDTitleLbl);
			jobIDTitleLbl.setText("Job ID:");
			jobIDTitleLbl.setBounds(31, 107, 152, 25);
			jobIDTitleLbl.setFont(new java.awt.Font("Arial",0,18));
			jobIDTitleLbl.setToolTipText("Job ID");
			jobIDTitleLbl.setHorizontalAlignment(SwingConstants.LEFT);
			jobIDTitleLbl.setVerticalAlignment(SwingConstants.BOTTOM);
			jobIDTitleLbl.setVerticalTextPosition(SwingConstants.BOTTOM);		
		
			jobIDLbl = new JLabel();
			this.add(jobIDLbl);
			jobIDLbl.setText("Job123456");
			jobIDLbl.setBounds(221, 107, 152, 25);
			jobIDLbl.setFont(new java.awt.Font("Arial",0,18));
			jobIDLbl.setToolTipText("Job ID");
			jobIDLbl.setHorizontalAlignment(SwingConstants.LEFT);
			jobIDLbl.setVerticalAlignment(SwingConstants.BOTTOM);
			jobIDLbl.setVerticalTextPosition(SwingConstants.BOTTOM);
		
			statusLbl = new JLabel();
			this.add(statusLbl);
			statusLbl.setText("Job Status:");
			statusLbl.setBounds(31, 144, 122, 25);
			statusLbl.setVerticalAlignment(SwingConstants.BOTTOM);
			statusLbl.setVerticalTextPosition(SwingConstants.BOTTOM);
			statusLbl.setFont(new java.awt.Font("Arial",0,18));
			statusLbl.setHorizontalAlignment(SwingConstants.LEFT);
		
			ComboBoxModel isStatusCbxModel = 
				new DefaultComboBoxModel(
						new String[] { "Active", "Deleted" });
			isStatusCbx = new JComboBox();
			this.add(isStatusCbx);
			isStatusCbx.setModel(isStatusCbxModel);
			isStatusCbx.setBounds(223, 146, 150, 25);
			isStatusCbx.setToolTipText("Active Job Status");
			isStatusCbx.setOpaque(false);
			isStatusCbx.setFont(new java.awt.Font("Arial",0,18));
			isStatusCbx.setEnabled(false);
		
			jobTitleLbl = new JLabel();
			this.add(jobTitleLbl);
			jobTitleLbl.setText("Job Title:");
			jobTitleLbl.setBounds(31, 181, 122, 25);
			jobTitleLbl.setHorizontalAlignment(SwingConstants.LEFT);
			jobTitleLbl.setVerticalAlignment(SwingConstants.BOTTOM);
			jobTitleLbl.setVerticalTextPosition(SwingConstants.BOTTOM);
			jobTitleLbl.setFont(new java.awt.Font("Arial",0,18));
		
			titleTextField = new JTextField();
			titleTextField.setText("Manager");
			titleTextField.setBounds(223, 181, 150, 28);
			titleTextField.setFont(new java.awt.Font("Arial",0,15));
		
			jobDescriptionTitleLbl = new JLabel();
			this.add(jobDescriptionTitleLbl);
			jobDescriptionTitleLbl.setText("Job Description:");
			jobDescriptionTitleLbl.setBounds(31, 218, 150, 25);
			jobDescriptionTitleLbl.setFont(new java.awt.Font("Arial",0,18));
			jobDescriptionTitleLbl.setHorizontalAlignment(SwingConstants.LEFT);
			jobDescriptionTitleLbl.setVerticalAlignment(SwingConstants.BOTTOM);
			jobDescriptionTitleLbl.setVerticalTextPosition(SwingConstants.BOTTOM);
		
			descriptionTxtArea = new JTextArea();
			this.add(descriptionTxtArea);
			descriptionTxtArea.setText("this is about job description");
			descriptionTxtArea.setBounds(223, 220, 185, 131);
			descriptionTxtArea.setFont(new java.awt.Font("Arial",0,15));
		
			yearsOfExpTitleLbl = new JLabel();
			this.add(yearsOfExpTitleLbl);
			yearsOfExpTitleLbl.setText("Years of Experience:");
			yearsOfExpTitleLbl.setBounds(28, 366, 181, 21);
			yearsOfExpTitleLbl.setFont(new java.awt.Font("Arial",0,18));
			yearsOfExpTitleLbl.setHorizontalAlignment(SwingConstants.LEFT);
			yearsOfExpTitleLbl.setVerticalAlignment(SwingConstants.BOTTOM);
			yearsOfExpTitleLbl.setVerticalTextPosition(SwingConstants.BOTTOM);
		
			yearsOfExpTxtField = new JTextField();
			this.add(yearsOfExpTxtField);
			yearsOfExpTxtField.setText("6");
			yearsOfExpTxtField.setBounds(221, 362, 185, 28);
			yearsOfExpTxtField.setFont(new java.awt.Font("Arial",0,18));
		
			startDateLbl = new JLabel();
			this.add(startDateLbl);
			startDateLbl.setText("Start Date:");
			startDateLbl.setBounds(28, 409, 166, 21);
			startDateLbl.setFont(new java.awt.Font("Arial",0,18));
		
			startDateTxtField = new JTextField();
			this.add(startDateTxtField);
			startDateTxtField.setText("1st Jan 2012");
			startDateTxtField.setBounds(221, 405, 185, 28);
			startDateTxtField.setFont(new java.awt.Font("Arial",0,18));
		
			skillsLbl = new JLabel();
			this.add(skillsLbl);
			skillsLbl.setText("Skills:");
			skillsLbl.setBounds(444, 95, 109, 21);
			skillsLbl.setFont(new java.awt.Font("Arial",0,18));
			
			ListModel skillsJListModel = 
				new DefaultComboBoxModel(
						new String[] { "Technical", "Presentation" });
			skillsJList = new JList();
			this.add(skillsJList);
			skillsJList.setModel(skillsJListModel);
							
			skillsJList.setBounds(559, 95, 213, 88);
			skillsJList.setFont(new java.awt.Font("Arial",0,15));
			skillsJList.setVisibleRowCount(12);
			skillsJList.setToolTipText("Select Skills");
		
			locationLbl = new JLabel();
			this.add(locationLbl);
			locationLbl.setText("Location:");
			locationLbl.setBounds(444, 222, 84, 21);
			locationLbl.setFont(new java.awt.Font("Arial",0,18));
			ListModel locationJListModel = 
				new DefaultComboBoxModel(
						new String[] { "Singapore", "America" });
			locationJList = new JList();
			this.add(locationJList);
			locationJList.setModel(locationJListModel);
			
			locationJList.setBounds(557, 222, 216, 109);
			locationJList.setFont(new java.awt.Font("Arial",0,15));
			locationJList.setToolTipText("Select Job Location");
			locationJList.setVisibleRowCount(12);
		
			salaryRangeLbl = new JLabel();
			this.add(salaryRangeLbl);
			salaryRangeLbl.setText("Salary Range:");
			salaryRangeLbl.setBounds(440, 366, 123, 21);
			salaryRangeLbl.setFont(new java.awt.Font("Arial",0,18));
		
			ComboBoxModel salaryRangeCbxModel = 
				new DefaultComboBoxModel(
						new String[] { "S$1000 - S$2000", "S$2000 - S$4000" });
			salaryRangeCbx = new JComboBox();
			this.add(salaryRangeCbx);
			salaryRangeCbx.setModel(salaryRangeCbxModel);
			salaryRangeCbx.setBounds(589, 362, 184, 28);
			salaryRangeCbx.setEditable(true);
		
			hideSalaryLbl = new JLabel();
			this.add(hideSalaryLbl);
			hideSalaryLbl.setText("Hide Salary:");
			hideSalaryLbl.setBounds(440, 409, 109, 21);
			hideSalaryLbl.setFont(new java.awt.Font("Arial",0,18));
		
			ComboBoxModel isHideSalaryCbxModel = 
				new DefaultComboBoxModel(
						new String[] { "Yes", "No" });
			isHideSalaryCbx = new JComboBox();
			this.add(isHideSalaryCbx);
			isHideSalaryCbx.setModel(isHideSalaryCbxModel);
			isHideSalaryCbx.setBounds(589, 407, 181, 28);
			isHideSalaryCbx.setFont(new java.awt.Font("Arial",0,15));
		
	}	
	public Date getCreationDate() {
		String creationDate = creationDateLbl.getText();
		
		Date createdDate = null;		
		DateFormat df = new SimpleDateFormat("dd-MMM-YYYY");
		
		try {
			createdDate = df.parse(creationDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return createdDate;		
	}
	public int getJobID() {
		String jobId = jobIDLbl.getText();
		int id = Integer.parseInt(jobId);
		
		return id;
	}
	public Boolean getIsStatus(){
		Object status = (String) isStatusCbx.getSelectedItem();
		
		Boolean jobStatus = null;
		
		if(status.equals("ACTIVE"))
			jobStatus = true;
		else
			jobStatus = false;
			
		return jobStatus;
	}		
	public String getJobDescription() {
		return descriptionTxtArea.getText();
	}	
	public String getYearsOfExp() {
		return yearsOfExpTxtField.getText();
	}	
	public Date getStartDate() {
		String startDate = startDateTxtField.getText();
		
		Date stDate = null;		
		DateFormat df = new SimpleDateFormat("dd-MMM-YYYY");
		
		try {
			stDate = df.parse(startDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return stDate;	
	}	
	public String getSalaryRange() {
		return (String)salaryRangeCbx.getSelectedItem();
	}	
	public boolean getIsHideSalary() {
		
		String status = (String)isHideSalaryCbx.getSelectedItem();
		boolean salaryStatus = false;
		
		if(status.equals("Yes")){
			salaryStatus = true;
		}
		
		return salaryStatus;	
	}	
	public String getJobTitle() {
		return titleTextField.getText();
	}
	public void resetTextEntries(){
		titleTextField.setText("");
		startDateTxtField.setText("");
		yearsOfExpTxtField.setText("");	
		
		descriptionTxtArea.setText("");
	}
	public void setSkills(List<Skill> skills) {
		this.skills = skills;
	}

	public void setCompanies(List<Company> companies) {
		this.companies = companies;
	}
	
	public void setLocations(List<GeographicalLocation> locations) {
		this.locations = locations;
	}
	public void setJobAdvertisementController(JobAdvertisementController controller){
		this.jobAdvertisementController = controller;
	}
	

}
